package cn.net.susan.seckill.business.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

/**
 * RestTemplate配置类
 *
 * @author 苏三，该项目是知识星球：java突击队 的内部项目
 * @date 2024/7/28 上午10:28
 */
@Configuration
public class RestTemplateConfig {

    @Value("${seckill.api.restTemplate.connectTimeout:200000}")
    private int connectTimeout;

    @Value("${seckill.api.restTemplate.readTimeout:200000}")
    private int readTimeout;

    @Bean
    public RestTemplate restTemplate() {
        SimpleClientHttpRequestFactory httpRequestFactory = new SimpleClientHttpRequestFactory();
        httpRequestFactory.setConnectTimeout(connectTimeout);
        httpRequestFactory.setReadTimeout(readTimeout);
        return new RestTemplate(httpRequestFactory);
    }
}
